Policies_Overlay_Link_Focus = Class.create({
    bound_handler_method_ : '',
    event_node_ : '',
    close_link_id_ : '',
    overlay_focus_id_: '',
    calling_class_ : '',
    initialize: function(element, close_link_id, overlay_focus_id, calling_class) 
    {
        this.event_node_ = element;
        this.close_link_id_ = close_link_id;
        this.overlay_focus_id_ = overlay_focus_id.toString();
        this.calling_class_ = calling_class;
        this.bound_handler_method_ = this.keyboardInput.bind(this);
        this.makeLinksInactive();
        document.observe('keydown', this.bound_handler_method_);
        $(this.overlay_focus_id_).focus();
    },
    keyboardInput: function(event)
    {
        var keycode = event.keyCode;
        var escape_key;
        if (event.DOM_VK_ESCAPE) {
            escape_key = event.DOM_VK_ESCAPE;
        } else { // ie
            escape_key = 27;
        }
        if(event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40)
            event.stop();
        if(keycode == escape_key)
            this.calling_class_.closeWindow(event);
    },
    makeLinksInactive : function()
    {
        $$('a').each(function(link){
            if(link.readAttribute('tabindex') == null && (link.readAttribute('id') == null || (link.readAttribute('id') != this.close_link_id_ && link.readAttribute('id') != this.overlay_focus_id_)))
            {
                link.writeAttribute({'tabindex': '-1'});
                link.addClassName('pol-overlay-inactive');
            }
        }.bind(this));
        $$('input').each(function(input){
            input.writeAttribute({'tabindex': '-1'});
            input.addClassName('pol-overlay-inactive');
        });
        $$('select').each(function(input){
            input.writeAttribute({'tabindex': '-1'});
            input.addClassName('pol-overlay-inactive');
        });
    },
    makeLinksActive : function()
    {
        $$('.pol-overlay-inactive').each(function(element){
            element.writeAttribute({'tabindex': null});
            element.removeClassName('lightbox-inactive');
        });
    },
    closeOverlay : function()
    {
        this.makeLinksActive();
        this.event_node_.focus();
        document.stopObserving('keydown', this.bound_handler_method_);
    }
});
